package com.lynn.salary.web.interceptor;

import java.sql.SQLException;

import com.lynn.salary.pojo.LoginUser;
import com.lynn.salary.util.DBUtil;
import com.lynn.salary.util.ObjectFactory;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class LoginInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		LoginUser u = (LoginUser)arg0.getInvocationContext().getSession().get("loginUser");
		if(u == null) {
			System.out.println("拦截未登录操作...");
			return "login";
		}
		return arg0.invoke();
	}

	@Override
	public void destroy() {
		System.out.println(" $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $");
		System.out.println("\t\tdestory system operation is on going ...");
		try {
			DBUtil.destory();
		} catch (SQLException e) {
			System.out.println("\t\tdestory DBUtil is fail ...");
//			e.printStackTrace();
		}
		ObjectFactory.destory();
		System.out.println(" $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $");
		
		super.destroy();
	}

}
